﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="PageTitle" runat="server">
    <title>发送新信件</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="PageStyles" runat="server">
    <link href="../../Content/Message/message.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        #divReceiver
        {
            border: solid 1px #ccc;
            margin-top: -1px;
            margin-bottom: 3px;
            border-radius: 4px;
        }
        #divReceiver
        {
        }
        #divReceiver ul
        {
            overflow: hidden;
            text-align: center;
        }
        #divReceiver li
        {
            clear: both;
        }
        #divReceiver ul li p
        {
            float: left;
            min-width: 100px;
        }
        .formBox .strong-box
        {
            padding: 6px 3px 0;
            width: 25px;
            font-weight: bold;
            vertical-align: top;
            text-align: right;
            color: #444;
            white-space: nowrap;
        }
        .formBox .r
        {
            margin-top: 14px;
        }
        
        .formBox table .ui-button-icon-only
        {
            margin-top: -10px;
        }
        .formBox .is-need-confirm
        {
            color: #2E76C5;
        }
        .labl-content
        {
            margin-left: -3px;
            display: inline-block;
            width: auto;
        }
        .pnlIsNeedConfirm
        {
            font-size: 14px;
        }
    </style>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PageScripts" runat="server">
    <link href="../../Content/userInfoSelect.css" rel="stylesheet" type="text/css" />
    <script src="../../Content/xheditor/xheditor-zh-cn.js" type="text/javascript"></script>
    <script type="text/javascript">

        //************* URL常量

        var URL_MESSAGE_SEND = '/Message/DoSend';

        //************* 全局变量

        var g_Var = {
            'currentTime': null,
            'currentUser': null,
            'recieverId': null,
            '_pinyin': new Pinyin()

        };

        //************* 常量定义

        //************* Accessor访问器

        var EzAccessor = {};

        if (ezmock.IS_MOCKED) {


        } else {
            var realEzAccessor = {

                'doSendMessage': function () {
                    //获得标题
                    var title = $('#messageTitle').val();
                    //获得内容
                    var text = $('#messageContent').val();
                    //获得是否需要确认
                    var needConfirm = $('#chk-need-confirm').attr("checked");
                    //获得收件人名单
                    memberString = g_Var['recieverId'];
                    //发送信件
                    $('.page-submit').ajaxBusyProgress();

                    $.post(URL_MESSAGE_SEND,
                        {
                            'memberString': memberString,
                            'messageTitle': title,
                            'messageText': text,
                            'needConfirm': needConfirm
                        }, function (e) {
                            if (e.Status == "Success") {
                                var url = '/message/show?topicId={topicId}';
                                url = url.replace("{topicId}", e.Data.topicId);
                                $.redirectAndDisplayInfo(url, e);
                            } else {
                                $('.page-submit').ajaxBusyProgress('reset');
                            }
                        });

                }
            };

            EzAccessor = realEzAccessor;
        }
        
        function checkForm() {
            // 判断标题长度
            if ($("#messageTitle").val().trim().length > 30) {
                var StatusInfo = { 'Status': 'Error', 'Info': '信件标题太长了，要求小于30个字符！', 'Data': null };
                $.displayStatusInfo(StatusInfo);
                return false;
            }

            //判断回复是否为空
            if ($("#messageContent").val().trim().length == 0) {
                var StatusInfo = { 'Status': 'Error', 'Info': '信件内容不能为空!', 'Data': null };
                $.displayStatusInfo(StatusInfo);
                return false;
            }

            //没有选择收件人
            if (g_Var.recieverId.trim().length == 0) {
                var StatusInfo = { 'Status': 'Error', 'Info': '没有选择收件人!', 'Data': null };
                $.displayStatusInfo(StatusInfo);
                return false;
            }

            return true;

        }


        function initPageEvent() {
            var userList;
            EzDesk.Service.GetAllUserInfo_CacheSync(function (e) {
                userList = e;
            });

            var groupList;
            EzDesk.Service.GetAllGroups_CacheSync(function (e) {
                groupList = e;
            });

            $("#messageReceiver").usersAutocomplete({
                width: '99%',
                userData: userList,
                groupData: groupList,
            });
            
            // 创建发送信件按钮的点击事件
            $('#btnSubmit').click(function () {
                g_Var['recieverId'] = $("#messageReceiver").usersAutocomplete('getIdList');
                var messageConfirm = checkForm();
                if (messageConfirm) {
                    EzAccessor.doSendMessage();
                }
            });

            $('#btnSendAndGo').click(function () {
                var messageConfirm = checkForm();
                if (messageConfirm) {
                    alert('这个功能还没实现。');
                }
            });
            //重设
            $('#btn-recover').click(function () {
                //清空标题和内容
                $('#messageTitle').clearFields();
                $('#messageContent').val("");
                //重设memberSelcet
                //chooseMembersCallBack(null);
                //取消选中的信件需要确认
                $('#chk-need-confirm').attr('checked', '');
                EzTipsManager.hideTipBox('tipNeedConfirm');
                //隐藏标题
                $('#deleTtiel').parent().hide();
                $('#addTitel').show();
            });
            
            $('#addLine').click(function () {
                var height = $('#xhe0_iframe').height();
                if (height <= 540) {
                    $('#xhe0_iframe').height(height + 80);
                }
            });

            $('#subtractLine').click(function () {
                var height = $('#xhe0_iframe').height();
                if (height >= 300) {
                    $('#xhe0_iframe').height(height - 80);
                }
            });

            $('#chk-need-confirm').change(function () {
                var isNeedConfirm = $('#chk-need-confirm').attr('checked');
                if (isNeedConfirm) {
                    $('#pnlIsNeedConfirm').addClass('is-need-confirm');

                } else {
                    $('#pnlIsNeedConfirm').removeClass('is-need-confirm');
                }
            });

        }



        function initPage() {
           
            $('#messageContent').xheditor({ tools: 'Fontface,FontSize,Bold,Italic,Underline,FontColor,BackColor,Align,Emot' });
            
        }


        $(function () {
            initPage();
            initPageEvent();
        });

    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="PageHead" runat="server">
    <%
        Html.RenderPartial("_sayHello"); %>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="PageContent" runat="server">
    <div id="page-head" class="page-head">
        <div id="links">
            <a href="/message/inbox" class="head">回到收件箱</a>
        </div>
        <img src="../../Content/icons/message_send.png" style="width: 48px; height: 48px;"
            alt="send" />
        <span class="title">写新信件</span>
    </div>
    <div id="page-body" style="overflow: hidden;">
        <div>
        </div>
        <div id="divReceiver" style="display: none;">
        </div>
        <div class="formBox" style="margin-top: 5px;">
            <table style="width: 100%">
                <tr>
                    <td class="strong-box">
                        <strong>收件人:</strong>
                    </td>
                    <td>
                        <div id="messageReceiver" class="ez-usbox">
                        </div>
                    </td>
                </tr>
                <tr>
                    <td class="strong-box">
                        <strong>标题:</strong>
                    </td>
                    <td>
                        <input type="text" id="messageTitle" class="txt-content" style="width: 99%;" />
                    </td>
                </tr>
                <tr>
                    <td class="strong-box">
                    </td>
                    <td>
                        <div id="pnlIsNeedConfirm" class="labl-content">
                            <label id="Label1" for="chk-need-confirm">
                                <input type="checkbox" id="chk-need-confirm" checked />需要确认</label></div>
                        <div style="float: right; margin-top: 4px;">
                            <div id="addLine" alt="send">增加行数</div>
                            <div id="subtractLine" alt="send">减少行数</div>
                            <script>
                                $(function () {
                                    $("#addLine").button({
                                        icons: {
                                            primary: "ui-icon-circle-plus"
                                        },
                                        text: false
                                    });
                                    $("#subtractLine").button({
                                        icons: {
                                            primary: "ui-icon-circle-minus"
                                        },
                                        text: false
                                    });
                                });
                            </script>
                        </div>
                    </td>
                </tr>
            </table>
            <div id="text">
                <textarea id="messageContent" style="width: 100%; height: 300px;"></textarea>
            </div>
        </div>
    </div>
    <div class="page-submit">
        <button id="btnSubmit">
            发送
        </button>
        <script>
            $(function () {
                $("#btnSubmit").button({ icons: { primary: "ui-icon-circle-arrow-e" }, text:
                        true
                });
            }); </script>
        &nbsp;或者&nbsp;<a id="btn-recover">重置</a>
    </div>
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="PageShortcut" runat="server">
</asp:Content>
<asp:Content ID="Content7" ContentPlaceHolderID="PageFoot" runat="server">
    <div id="tip_NeedConfirm" style="display: none;" class="tip-info">
        <h1>
            该信件需要被确认！</h1>
    </div>
</asp:Content>
